package config.indoor.nexd.com.nexdmapconfig.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import config.indoor.nexd.com.nexdmapconfig.model.Mall;

/**
 * Created by wangxu on 16/2/24.
 */
public class CheckedMallAdapter extends BaseAdapter {


    private List<Mall> malls = new ArrayList<>();

    private Context context;

    public CheckedMallAdapter(Context context) {
        this.context = context;
    }

    public void addMalls(List<Mall> malls) {
        this.malls.clear();
        this.malls.addAll(malls);
        this.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return malls.size();
    }

    @Override
    public Object getItem(int position) {
        return malls.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, android.R.layout.simple_list_item_1, null);
            holder.textView = (TextView) convertView.findViewById(android.R.id.text1);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.textView.setText(malls.get(position).getMallName());
        if ((position & 1) == 1) {
            holder.textView.setBackgroundResource(android.R.color.white);
        } else {
            holder.textView.setBackgroundResource(android.R.color.darker_gray);
        }
        return convertView;
    }

    private static class ViewHolder {
        private TextView textView;
    }
}
